package com.mentaleye.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.DormitorysBean;
import com.mentaleye.dal.dao.DormitoryDao;
import com.mentaleye.dal.model.Dormitorys;
import com.mentaleye.service.DormitoryService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.ObjectUtil;
@Service
public class DormitoryServiceImpl implements DormitoryService {

	@Autowired private DormitoryDao dormitoryDao;
	@Override
	public boolean addDormitory(DormitorysBean dormitoryBean) {
		if(dormitoryBean.getRestBed()==null){
			dormitoryBean.setRestBed(0);
		}
		Dormitorys dormitory = (Dormitorys) ObjectUtil.transfer(dormitoryBean, Dormitorys.class);
		return dormitoryDao.insertDormitory(dormitory);
	}

	@Override
	public boolean editDormitory(DormitorysBean dormitoryBean) {
		Dormitorys dormitory = (Dormitorys) ObjectUtil.transfer(dormitoryBean, Dormitorys.class);
		return dormitoryDao.modifyDormitory(dormitory);
	}

	@Override
	public boolean removeDormitory(List<Integer> dorId) {
		return dormitoryDao.deleteDormitory(dorId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DormitorysBean> getAllDirmitory() {
		return ObjectUtil.transferList(dormitoryDao.queryAllDormitory(), DormitorysBean.class);
	}

	@Override
	public void getDormitoryByPage(CommonPage commonPage) {
		@SuppressWarnings("unchecked")
		List<DormitorysBean> data=  ObjectUtil.transferList(dormitoryDao.queryDormitory(commonPage.pageToMap()),DormitorysBean.class);
		commonPage.setPageData(data);
	}

	@Override
	public DormitorysBean getDormitoryById(Integer dorId) {
		return (DormitorysBean) ObjectUtil.transfer(dormitoryDao.queryDormitoryById(dorId), DormitorysBean.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DormitorysBean> getDormitoryWithRest() {
		return ObjectUtil.transferList(dormitoryDao.queryDormitoryWithRest(), DormitorysBean.class);
	}



}
